package md.lanjing.com.module_mine.contact;

import android.content.Context;


import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;
import com.lxh.baselibray.util.Md5Utils;
import com.lxh.baselibray.util.SPUtils;
import com.lxh.baselibray.util.ToastUtils;



import com.lxh.baselibray.constant.Constant;

import md.lanjing.com.module_mine.R;
import md.lanjing.com.module_mine.api.MineApiService;
import md.lanjing.com.module_mine.bean.ModifyLoginPwdRequest;
import md.lanjing.com.module_mine.bean.ModifyLoginPwdResponse;
import retrofit2.Call;
import retrofit2.Response;

public class ModifyLoginPwdContact {

    public static class ModifyLoginPwdPresent extends BasePresent<IModifyLoginPwdView> {
        public void modifyLoginPwd(final Context context, String oldPwd, String newPwd){
            MineApiService service= ServiceGenerator.createService(MineApiService.class);
            int userId = SPUtils.getInt(Constant.USER_ID, -1, context);
            ModifyLoginPwdRequest request=new ModifyLoginPwdRequest(userId, Md5Utils.stringToMD5(oldPwd), Md5Utils.stringToMD5(newPwd));
            service.modifyLoginPwd(request).enqueue(new NetCallBack<ModifyLoginPwdResponse>() {
                @Override
                public void onSuccess(Call<ModifyLoginPwdResponse> call, Response<ModifyLoginPwdResponse> response) {
                    if (getView()!=null){
                        getView().getModifyLoginPwdData(response);
                    }
                }

                @Override
                public void onFailed() {
                    ToastUtils.showLongToast(context,context.getString(R.string.request_failed));
                }
            });

        }
    }

    public interface IModifyLoginPwdView extends IBaseView {
        void getModifyLoginPwdData(Response<ModifyLoginPwdResponse> response);

    }
}
